package com.jiuzhou.guanwang.jzcp.activity;

import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

import com.jiuzhou.guanwang.jzcp.R;
import com.jiuzhou.guanwang.jzcp.base.WebFragment;

public class TrandActivity extends AppCompatActivity implements View.OnClickListener {
    private WebFragment m3dFragment;
    private TextView m3dTv;
    private View m3dView;
    private WebFragment mCurrentFragment;
    private WebFragment mDltFragment;
    private TextView mDltTv;
    private View mDltView;
    private WebFragment mPlsFragment;
    private TextView mPlsTv;
    private View mPlsView;
    private WebFragment mSsqFragment;
    private TextView mSsqTv;
    private View mSsqView;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView((int) R.layout.activity_trand);
        Window window = getWindow();
        initView();
        initData();
    }

    private void initView() {
        this.mSsqTv = (TextView) findViewById(R.id.tv_ssq);
        this.mSsqView = findViewById(R.id.view_ssq);
        this.m3dTv = (TextView) findViewById(R.id.tv_3d);
        this.m3dView = findViewById(R.id.view_3d);
        this.mDltTv = (TextView) findViewById(R.id.tv_dlt);
        this.mDltView = findViewById(R.id.view_dlt);
        this.mPlsTv = (TextView) findViewById(R.id.tv_pls);
        this.mPlsView = findViewById(R.id.view_pls);
        findViewById(R.id.rl_ssq).setOnClickListener(this);
        findViewById(R.id.rl_3d).setOnClickListener(this);
        findViewById(R.id.rl_dlt).setOnClickListener(this);
        findViewById(R.id.rl_pls).setOnClickListener(this);
    }
    public void back(View targv) {
        finish();
    }

    private void initData() {
        this.mSsqFragment = new WebFragment();
        Bundle bundle = new Bundle();
        bundle.putString("url", "http://m.500.com/datachart/ssq/jb.html");
        this.mSsqFragment.setArguments(bundle);
        this.m3dFragment = new WebFragment();
        Bundle bundle1 = new Bundle();
        bundle1.putString("url", "http://m.500.com/datachart/sd/jb.html");
        this.m3dFragment.setArguments(bundle1);
        this.mDltFragment = new WebFragment();
        Bundle bundle2 = new Bundle();
        bundle2.putString("url", "http://m.500.com/datachart/dlt/qianqu.html");
        this.mDltFragment.setArguments(bundle2);
        this.mPlsFragment = new WebFragment();
        Bundle bundle3 = new Bundle();
        bundle3.putString("url", "http://m.500.com/datachart/pls/jb.html");
        this.mPlsFragment.setArguments(bundle3);
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        ft.add((int) R.id.fl_container, this.mSsqFragment);
        this.mCurrentFragment = this.mSsqFragment;
        ft.commit();
    }

    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.rl_3d:
                if (this.m3dFragment.isAdded()) {
                    getSupportFragmentManager().beginTransaction().hide(this.mCurrentFragment).show(this.m3dFragment).commit();
                } else {
                    getSupportFragmentManager().beginTransaction().hide(this.mCurrentFragment).add((int) R.id.fl_container, this.m3dFragment).commit();
                }
                this.mCurrentFragment = this.m3dFragment;
                setTabStatus(R.id.rl_3d);
                return;
            case R.id.rl_dlt:
                if (this.mDltFragment.isAdded()) {
                    getSupportFragmentManager().beginTransaction().hide(this.mCurrentFragment).show(this.mDltFragment).commit();
                } else {
                    getSupportFragmentManager().beginTransaction().hide(this.mCurrentFragment).add((int) R.id.fl_container, this.mDltFragment).commit();
                }
                this.mCurrentFragment = this.mDltFragment;
                setTabStatus(R.id.rl_dlt);
                return;
            case R.id.rl_pls:
                if (this.mPlsFragment.isAdded()) {
                    getSupportFragmentManager().beginTransaction().hide(this.mCurrentFragment).show(this.mPlsFragment).commit();
                } else {
                    getSupportFragmentManager().beginTransaction().hide(this.mCurrentFragment).add((int) R.id.fl_container, this.mPlsFragment).commit();
                }
                this.mCurrentFragment = this.mPlsFragment;
                setTabStatus(R.id.rl_pls);
                return;
            case R.id.rl_ssq:
                if (this.mSsqFragment.isAdded()) {
                    getSupportFragmentManager().beginTransaction().hide(this.mCurrentFragment).show(this.mSsqFragment).commit();
                } else {
                    getSupportFragmentManager().beginTransaction().hide(this.mCurrentFragment).add((int) R.id.fl_container, this.mSsqFragment).commit();
                }
                this.mCurrentFragment = this.mSsqFragment;
                setTabStatus(R.id.rl_ssq);
                return;
            default:
                return;
        }
    }

    private void setTabStatus(int id) {
        switch (id) {
            case R.id.rl_3d:
                this.mSsqTv.setTextColor(getResources().getColor(R.color.common_60));
                this.m3dTv.setTextColor(getResources().getColor(R.color.red));
                this.mDltTv.setTextColor(getResources().getColor(R.color.common_60));
                this.mPlsTv.setTextColor(getResources().getColor(R.color.common_60));
                this.mSsqView.setBackgroundColor(getResources().getColor(R.color.circle_remark_publish_bg));
                this.m3dView.setBackgroundColor(getResources().getColor(R.color.red));
                this.mDltView.setBackgroundColor(getResources().getColor(R.color.circle_remark_publish_bg));
                this.mPlsView.setBackgroundColor(getResources().getColor(R.color.circle_remark_publish_bg));
                return;
            case R.id.rl_dlt:
                this.mSsqTv.setTextColor(getResources().getColor(R.color.common_60));
                this.m3dTv.setTextColor(getResources().getColor(R.color.common_60));
                this.mDltTv.setTextColor(getResources().getColor(R.color.red));
                this.mPlsTv.setTextColor(getResources().getColor(R.color.common_60));
                this.mSsqView.setBackgroundColor(getResources().getColor(R.color.circle_remark_publish_bg));
                this.m3dView.setBackgroundColor(getResources().getColor(R.color.circle_remark_publish_bg));
                this.mDltView.setBackgroundColor(getResources().getColor(R.color.red));
                this.mPlsView.setBackgroundColor(getResources().getColor(R.color.circle_remark_publish_bg));
                return;
            case R.id.rl_pls:
                this.mSsqTv.setTextColor(getResources().getColor(R.color.common_60));
                this.m3dTv.setTextColor(getResources().getColor(R.color.common_60));
                this.mDltTv.setTextColor(getResources().getColor(R.color.common_60));
                this.mPlsTv.setTextColor(getResources().getColor(R.color.red));
                this.mSsqView.setBackgroundColor(getResources().getColor(R.color.circle_remark_publish_bg));
                this.m3dView.setBackgroundColor(getResources().getColor(R.color.circle_remark_publish_bg));
                this.mDltView.setBackgroundColor(getResources().getColor(R.color.circle_remark_publish_bg));
                this.mPlsView.setBackgroundColor(getResources().getColor(R.color.red));
                return;
//            case R.id.rl_plw:
//                this.mSsqTv.setTextColor(getResources().getColor(R.color.common_60));
//                this.m3dTv.setTextColor(getResources().getColor(R.color.common_60));
//                this.mDltTv.setTextColor(getResources().getColor(R.color.common_60));
//                this.mPlsTv.setTextColor(getResources().getColor(R.color.common_60));
//                this.mSsqView.setBackgroundColor(getResources().getColor(R.color.circle_remark_publish_bg));
//                this.m3dView.setBackgroundColor(getResources().getColor(R.color.circle_remark_publish_bg));
//                this.mDltView.setBackgroundColor(getResources().getColor(R.color.circle_remark_publish_bg));
//                this.mPlsView.setBackgroundColor(getResources().getColor(R.color.circle_remark_publish_bg));
//                return;
            case R.id.rl_ssq:
                this.mSsqTv.setTextColor(getResources().getColor(R.color.red));
                this.m3dTv.setTextColor(getResources().getColor(R.color.common_60));
                this.mDltTv.setTextColor(getResources().getColor(R.color.common_60));
                this.mPlsTv.setTextColor(getResources().getColor(R.color.common_60));
                this.mSsqView.setBackgroundColor(getResources().getColor(R.color.red));
                this.m3dView.setBackgroundColor(getResources().getColor(R.color.circle_remark_publish_bg));
                this.mDltView.setBackgroundColor(getResources().getColor(R.color.circle_remark_publish_bg));
                this.mPlsView.setBackgroundColor(getResources().getColor(R.color.circle_remark_publish_bg));
                return;
            default:
                return;
        }
    }
}